//
//  MainViewController.swift
//  ZYBWeibo
//
//  Created by xthink4 on 16/1/11.
//  Copyright © 2016 zyb. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    @IBOutlet weak var mainTabBar: MainTabBar!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        addchildViewControllers()
        //添加按钮的响应事件
        self.mainTabBar.customButton.addTarget(self, action: "customBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
    }
    ///按钮的响应方法
    func customBtnClick(){
        print("\(__FUNCTION__)")
    }
    ///添加子视图控制器
    private func addchildViewControllers(){
        let titles=["首页","信息","发现","我"];
        let images=["tabbar_home","tabbar_message_center","tabbar_discover","tabbar_profile"];
        let selectImages=["tabbar_home_highlighted","tabbar_message_center_highlighted","tabbar_discover_highlighted","tabbar_profile_highlighted"];
        let controllers=["Home","Message","Discover","My"];
        //利用for 循环 将控制器添加在TabBar上
        for var index = 0; index < 4; ++index {
            let sb=UIStoryboard(name:controllers[index], bundle: nil)
            let nav=sb.instantiateInitialViewController()as!UINavigationController
            nav.topViewController?.title=titles[index]       //字体颜色
            //tabBar.tintColor=UIColor.orangeColor()
            nav.tabBarItem.image=UIImage(named:images[index])
            nav.tabBarItem.selectedImage=UIImage(named: selectImages[index])
            addChildViewController(nav)
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}
